#include <iostream>
#include <memory>
#include "udp_server.hpp"

const char *path = "./dict.txt";                        // static作用域：当前源文件

//./server serverip serverport
int main(int argc, char *argv[])
{
    if (argc != 2) // if (argc != 3)
    {
        std::cout << "Usage: ./xxx serverport" << std::endl; // std::cout << "Usage: ./xxx serverip serverport" << std::endl;
        exit(-1);
    }
    // std::string lockip = argv[1];
    uint16_t lockport = std::stoi(argv[1]);

    // UdpServer server;
    // server.InitServer(lockport);
    // server.Start();
    Dict dict(path);
    //std::cout << 1 << std::endl;
    func_t translate = std::bind(&Dict::Translate, dict, std::placeholders::_1);
    // std::unique_ptr<UdpServer> up_udpser = std::make_unique<UdpServer>();//make_unique是C++14的; 编辑器识别有问题，不用管
    std::unique_ptr<UdpServer> up_udpser = std::make_unique<UdpServer>(translate);//(new UdpServer());
    up_udpser->InitServer(lockport);
    up_udpser->Start();

    return 0;
}